<%@ page import="org.springframework.web.context.request.RequestScope" %>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>编辑角色</title>
    <link rel="stylesheet" href="/gzht/lib/Hui-iconfont/1.0.8/iconfont.min.css" media="all">
    <link rel="stylesheet" href="/gzht/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/gzht/lib/Hui-iconfont/1.0.8/iconfont.min.css" media="all">
    <link rel="stylesheet" href="/gzht/lib/layui/formselects/formSelects-v4.css">
</head>
<body style="background-color: #F2F2F2;padding: 1rem;">
<form class="layui-form" action="" style="width: 600px;">
    <input type="hidden" name="roleNo" value="${role.roleNo}">
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input type="text" name="roleName" required value="${role.roleName}"  lay-verify="required" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">分配权限</label>
            <div class="layui-input-inline" style="width: 360px;">
                <select name="roleLimit" id="roleLimit" lay-filter="roleLimit"
                        xm-select="roleLimit" xm-select-type="1">
                    <option value=""></option>
                    <c:set var="hasLimit" value="0"></c:set>
                    <c:forEach items="${limits}" var="limit">
                        <c:set var="hasLimit" value="0"></c:set>
                        <c:forEach items="${roleLimit}" var="roleLimit">
                            <c:if test="${roleLimit.roleLimitLimitNo.equals(limit.limitNo)}">
                                <c:set var="hasLimit" value="1"></c:set>
                            </c:if>
                        </c:forEach>
                        <c:choose>
                            <c:when test="${limit.limitStatus == 0}">
                                <c:if test="${hasLimit.equals('0')}">
                                    <option value="${limit.limitNo}">${limit.limitName}</option>
                                </c:if>
                                <c:if test="${hasLimit.equals('1')}">
                                    <option value="${limit.limitNo}" selected>${limit.limitName}</option>
                                </c:if>
                            </c:when>
                            <c:when test="${limit.limitStatus == 1}">
                                <c:if test="${hasLimit.equals('0')}">
                                    <option value="${limit.limitNo}" disabled>${limit.limitName}</option>
                                </c:if>
                                <c:if test="${hasLimit.equals('1')}">
                                    <option value="${limit.limitNo}" disabled selected>${limit.limitName}</option>
                                </c:if>
                            </c:when>
                        </c:choose>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <c:choose>
                <c:when test="${role.roleStatus == 0}">
                    <input type="checkbox" name="roleStatus" value="0" lay-skin="switch" lay-text="启用|禁用" checked>
                </c:when>
                <c:otherwise>
                    <input type="checkbox" name="roleStatus" value="0" lay-skin="switch" lay-text="启用|禁用">
                </c:otherwise>
            </c:choose>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="roleRemark" placeholder="请输入内容" class="layui-textarea">${role.roleRemark}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="roleEditSubmit">保存修改</button>
            <a href="javascript:window.history.back(-1);" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </div>
</form>
<script src="/gzht/statics/js/jquery-1.12.2.min.js"></script>
<script src="/gzht/lib/layui/layui.js"></script>
<script src="/gzht/lib/layui/formselects/formSelects-v4.js"></script>
<script>
    $(function () {
        layui.use(['table', 'form', 'tree'], function () {
            var form = layui.form
            form.render();
            //监听提交
            form.on('submit(roleEditSubmit)', function (data) {
                var data = JSON.stringify(data.field);
                console.log(data)
                $.ajax({
                    url:'/gzht/roleManager/editRole',
                    data:data,
                    type:'post',
                    dataType:'json',
                    contentType: 'application/json',
                    success: function (res) {
                        if(res.code == 1001){
                            layer.msg('保存成功', {
                                icon: 1,
                                time: 600
                            }, function(){
                                window.history.back(-1);
                            });
                        }else {
                            layer.msg(res.desc)
                        }
                    },
                    error: function (err) {
                        layer.msg("网络出错")
                    }
                })
                return false;
            })

        })
    })
</script>
</body>
</html>
